package train3;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

import day04.Student;
import homework1.Ant;
import homework1.Bee;
import homework1.DaYan;
import homework1.GeZi;
import homework1.Point;
import homework1.QiEr;
import homework1.Rectangle;
import train2.MyDianTi;
import train2.MyDoor;
import train2.OtherDoor;
import train2.RanQi;

public class Train02 {
	@Test
	public void test03() {
		int[] array  = {23, 56, 8, 99, 2};
		//假设array[0]即数组第一个数为最大值；
		int max = array[0];
		//for循环
		for (int i = 0; i < array.length; i++) {
			//若成立，假设是错的；
			if (max < array[i]) {
				//将最大值赋予新的；
				max = array[i];
			}
		}
		//输出最大值
		System.out.println(max);
	}
	
	
	//下三角形
	@Test
	public void test4() {
		for (int i = 1; i <= 6; i++) {
			for (int j = 0; j <= (i -1) ; j++) {
				System.out.print(" ");
			}
			for (int j = (13 - (2 * i)); j >= 1; j--) {
				System.out.print("*");
			}
			System.out.println();
		}
	}
	//上三角形；
	@Test
	public void test5() {
		for (int i = 1; i <= 6; i++) {
			for (int j = (6 - i); j >= 0; j--) {
				System.out.print(" ");
			}
			for (int j = 1; j <= (2 * i - 1); j++) {
				System.out.print("*");
			}
			System.out.println();
		}
		
	}
	
	@Test
	public void test06() {
		for(int i = 100; i <= 200; i++) {
			boolean isSuShu = true;
			for(int j = 2; j < i; j++) {
				if (i % j == 0 ) {
					isSuShu = false;
				
				break;
				
			    }
	
			
		    }
		if (isSuShu == true) {
			System.out.println(i + "是素数");
			
		}
	    }
    }  
	
	// 16、题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
	@Test
	public void test07() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length / 2; i++) {
			if(array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
			}
			
		}
		 
		if (isHuiWen == true) {
			System.out.println("是回文");
		}else {
			 System.out.println("bu是回文");
		}
	}
	
	
	// 17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。	
	@Test
	public void test08() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串:");
		String str = scanner.nextLine();
		char[] array = str.toCharArray();
		int letterCount = 0;
		int numberCount = 0;
		int blankCount = 0;
		int otherCount = 0;
		
		for (int i = 0; i < array.length; i++) {
			if  ((array[i] >= 'a' && array[i] <= 'z' ) 
					|| (array[i] >= 'A' && array[i] <= 'Z'  )) {
				letterCount++;
			}
			else if(array[i] >= '0' && array[i] <= '9' ) {
				numberCount++;
			}
			else if (array[i] == ' ') {
				blankCount++;
			}
			else {
				otherCount++;
			}
		}
		System.out.println("字母个数：" + letterCount );
		System.out.println("数字个数：" + numberCount );
		System.out.println("空格个数：" + blankCount );
		System.out.println("其他符号个数：" + otherCount );
	}
	
	
	//使用冒泡排序int[] = {23,4,56,78,99,22,67}
	@Test
	public void test09() {
		int[] array = {23,4,56,78,99,22,67};
		for(int i = 1; i < array.length; i++) {
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
					
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i] + "\t");
			
		}
	}
	
	
	//求int[] = {23,4,56,78,99,22,67}最大值最小值
	@Test
	public void test10() {
		int[] array = {23,4,56,78,99,22,67};
		int max = array[0];
		for (int i = 1; i < array.length; i++) {
			if (array[i] > max) {
				max = array[i];
			}
		}
		System.out.println("最大值为：" + max);
		int min = array[0];
		for (int i = 1; i < array.length; i++) {
			if (array[i] < min) {
				min = array[i];
			}
		}
		System.out.println("最xiao值为：" + min);
	}
	
	
	// 求出上面数组中0-9分别出现的次数（有一点难度）

	// int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
	@Test
	public void test11() {
		int[] array = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] counts =new int[10];
		for (int i = 0; i < array.length; i++ ) {
			switch (array[i]) {
			case 0:
				counts[0]++;
				break;
			case 1:
				counts[1]++;
				break;
			case 2:
				counts[2]++;
				break;
			case 3:
				counts[3]++;
				break;
			case 4:
				counts[4]++;
				break;
			case 5:
				counts[5]++;
				break;
			case 6:
				counts[6]++;
				break;
			case 7:
				counts[7]++;
				break;
			case 8:
				counts[8]++;
				break;
			case 9:
				counts[9]++;
				break;
			default:
				break;
				
			}
		}
		

		for (int i = 0; i < counts.length; i++) {
			System.out.print(i + "出现的次数" + counts[i] + "\t");
	}
	
	
	
	
	
    }
	
	
	//九九乘法表的表示
	@Test
	public void test12() {
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= i; j++) {
				//doudou相加，变量不需要加双引号，字符以及 间隔“\t”需要双引号；
				System.out.print(j + "*" + i + "=" + (i * j ) + "\t");
			}
			System.out.println();
		}
		
	}
	
	@SuppressWarnings("null")
	@Test
	public void test13() {
		int[] array = null;//
		@SuppressWarnings("unused")
		int num = array[0];//NullPointerException
		Student student = null;
		//NullPointerException
		System.out.println(student.id);
	}
	
	//
	@Test
	public void test14() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();
		boolean isHuiWen = true;
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
			}
		}
		
		if (isHuiWen == true) {
			System.out.println("是回文");
		}
		else {
			System.out.println("不是回文");
		}
	}
	@Test
	public void test15() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();
		boolean isHuiWen = true;
		char[] array = str.toCharArray();
		
		for (int i = 0; i < array.length; i++) {
			if (array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
				
			}
		}
		if (isHuiWen == true) {
			System.out.println("是回文");
			
		}
		else {
			System.out.println("不是回文");
		}
	}
	
	@Test
	public void test16() {
		int[] array = {23,4,56,78,99,22,67};
		for(int i = 1; i < array.length; i++) {
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] < array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
					
				}
			}
	     }
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i] + "\t");
			
		}
	}
	
	@Test
	public void test17() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.print("请输入一个字符串：");
		String str = scanner.next();
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length; i++) {
			if (array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
				
			}
		}
		if (isHuiWen == true) {
			System.out.print("是回文");
		}
		else {
			System.out.print("不是回文");
		}
		
	}
	
	@Test
	public void test19() {
		Rectangle rectangle = new Rectangle(1, 2);
		rectangle.seekGirth();
		rectangle.seekArea();
	}
	@Test
	public void test20() {
		
		int dx = 4;
		int dy = 5;
		Point point = new Point(1,2);
		point.movePoint(dx, dy);
		System.out.print(point);
	}
	
	
	
	//接口抽象
	@Test
	public void test22() {
		QiEr qier = new QiEr();
		qier.egg();
		
	}
	@Test
	public void test23() {
		GeZi gezi = new GeZi();
		gezi.egg();
		gezi.fly();
	}
	@Test
	public void test24() {
		DaYan dayan = new DaYan();
		dayan.egg();
		dayan.fly();
	}
	@Test
	public void test25() {
		Bee bee = new Bee();
		bee.chanruan();
		bee.fly();
	}
	@Test
	public void test26() {
		Ant ant = new Ant();
			ant.chanruan();
	
	}
	//门
	@Test
	public void test27() {
		MyDoor mydoor = new MyDoor();
		mydoor.open();
		mydoor.close();
		mydoor.alarm();
	}
	@Test
	public void test28() {
		OtherDoor otherdoor = new OtherDoor();
		otherdoor.close();
		otherdoor.open();
		
	}
	@Test
	public void test29() {
		MyDianTi mydianti = new MyDianTi();
		mydianti.alarm();
		mydianti.down();
		mydianti.up();
	}
	@Test
	public void test30() {
		RanQi ranqi = new RanQi();
		ranqi.alarm();
	}
	@Test
	public void test31() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		int random = new Random().nextInt(500);
		System.out.println(random);
		for(; ;) {
			System.out.println("猜吧");
			int num = scanner.nextInt();
			if(num < random) {
				System.out.println("猜小了");
			
			}
			else if(num > random) {
				System.out.println("猜大了");
		
			}else {
				System.out.println("猜对了");
				break;
			}
		}
		
		
	}
	@Test
	public void test32() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		for(; ;) {
		System.out.println("请输入密码：");
		int num = scanner.nextInt();
	        if (num != 123) {
	        	System.out.println("密码错误");
			}
	        else
				System.out.println("密码正确");
			
	}
   }
	@Test
	public void test33() {
		for (int i = 1; i <= 6; i ++) {
			for (int j = 0; j <= 6 - i; j++ ) {
				System.out.print(" ");
			
			}
			for (int j = 1; j <= 2 * i -1; j++) {
				System.out.print("*");
			}
			
			System.out.println();
		}
	}
	@Test
	public void test34() {
		for(int i = 1; i <= 6 ; i++) {
			for (int j = 0; j <= i - 1; j++) {
				System.out.print(" ");
			}
			for (int j = 1; j <= 13 - (2 * i); j++) {
				System.out.print("*");
			}
			System.out.println();
		}
	}
	@Test
	public void test35() {
		char a = 'b';
		switch (a) {
		case 'b':
			System.out.println("T");
			
			break;
		case 'c':
			System.out.println("F");

		default:
			break;
		}
	}
	@Test
	public void test36() {
		String str = "z";
		switch (str) {
		case "z":
			System.out.println("T");
			break;
		case "f":
			System.out.println("F");

		default:
			break;
		}
		
	}
	@Test
	public void test37() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入月份：");
		int month = scanner.nextInt();
		switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			System.out.println("31天");
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			System.out.println("30天");
			break;
		case 2:
			System.out.println("请输入年份：");
			int year = scanner.nextInt();
			if (year % 4 == 0 && year % 100 != 0) {
				System.out.println("28天");
			}
			else {
				System.out.println("29");
			}
			break;

		default:
			break;
		}
	}
	@Test
	public void test38() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串:");
		String str = scanner.next();
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length / 2; i++ ) {
			if(array[i] != array[array.length - 1 -i]) {
				isHuiWen = false;
		
				
			}
			
			
		}
		if (isHuiWen == true) {
			System.out.println("是");
		}
		else {
			System.out.println("bushi");
		}
		
		
	}
	@Test
	public void test77() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length / 2; i++) {
			if(array[i] != array[array.length - 1 - i]) {
				isHuiWen = false;
				break;
			}
			
		}
		 
		if (isHuiWen == true) {
			System.out.println("是回文");
		}else {
			 System.out.println("bu是回文");
		}
	}
	@Test
	public void test39() {
		for (int i = 0; i < 5; i++) {
			if(i == 3) {
				continue;
			}
			System.out.println(i);
		}
		
		
	}
	
	
	@Test
	public void test40() {
		@SuppressWarnings("unused")
		int score1 = 85;
		@SuppressWarnings("unused")
		int score2 = 56;
		@SuppressWarnings("unused")
		int score3 = 78;
		@SuppressWarnings("unused")
		int[] array1 = {85, 56, 78};
		int[] array = new int[4];
		array[0] = 34;
		array[1] = 56;
		array[2] = 87;
		array[3] = 56;
		System.out.println(array.length);
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		
		for (int i = array.length - 1; i >= 0; i--) {
			System.out.println(array[i]);
		}
	}
	
	
	@Test
	public void test41() {
		int[] array = {23, 56, 8, 99, 2};
		int max = array[0];
		for (int i = 0; i < array.length; i++) {
			if (max < array[i]) {
				max = array[i];
				
			}
		}
		System.out.println("max: " + max);
	}


	@Test
	public void test42() {
		int[] array = {23, 56, 8, 99, 2};
		
		for (int i = 1; i < array.length; i++) {
			for (int j = 0; j < array.length - i; j++) {
				if (array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
			
			
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
	    }
	
	
	}
	
	
	
	@Test
	public void test43() {
		int[] array = {8, 56, 555, 4, 5, 12};
		// 外层循环控制比较多少趟
		for (int i = 1; i < array.length; i++) {
			// 如果左边的数比右边的数大，就交换这两个数的值
			for(int j = 0; j < array.length - 1; j++) {
				if (array[j] < array[j + 1] ) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		
	}
	
	@Test
	public void test44() {
		int[] scores={1, 5};
		int oddCount = 0;
		int evenCount = 0;
		for (int i = 0; i < scores.length; i++) {
			if(scores[i] % 2 == 0) {
				evenCount++;
			}
			else {
				oddCount++;
			}
		}
		System.out.println("奇数个数：" + oddCount);
		System.out.println("偶数个数：" + evenCount);
	}
	
	@Test
	public void test45() {
		int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] counts = new int[10];
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				counts[0]++;
				break;
			case 1:
				counts[1]++;
				break;
			case 2:
				counts[2]++;
				break;
			case 3:
				counts[3]++;
				break;
			case 4:
				counts[1]++;
				break;
			case 5:
				counts[5]++;
				break;
			case 6:
				counts[6]++;
				break;
			case 7:
				counts[7]++;
				break;
			case 8:
				counts[8]++;
				break;
			case 9:
				counts[9]++;
				break;
			default:
				break;
					
			}
			
		}
		for (int i = 0; i < counts.length; i++) {
			System.out.println(i + "出现的次数" + counts[i]);
		}
		
	    
        }
	@Test
	public void test46() {
		// 在方法里面定义的变量都叫局部变量 local variable
		@SuppressWarnings("unused")
		int temp = 2;
		for (int i = 0; i < 10; i++) {
			// Duplicate local variable i
			for (int j = 0; j < 34; j++) {
				
			}
		}
		
		for (int i = 0; i < 23; i++) {
			
		}
	}
	
	
	@Test
	public void test47() {
		for (int i = 100; i < 200; i++) {
			boolean isSuShu = true;
			for (int j = 2; j < i; j++) {
				if (i % j == 0) {
					isSuShu = false;
					break;
					
				}
			}
			if(isSuShu == true) {
				System.out.println(i + "是素数");
			}
			
			
		}
		
	}
	
	@Test
	public  void test48() {
		for(int i = 100 ; i <= 200; i++) {
			for(int j = 2;j < i; j++) {
				// 找到一个整除，不是素数，就退出
				if(i % j == 0) {
					break;
				}
				if(j == i - 1) {
					System.out.println(i + "是素数");
				}
			}
		}
	}
	
	
	@Test
	public void test49() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.next();
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length / 2; i++) {
			if (array[i] != array[array.length - 1 - i]){
				isHuiWen = false;
				break;
			}
			
		}
		if(isHuiWen == true) {
			System.out.println("是回文");
			
		}
		else {
			System.out.println("不是回文");
		}
		
	}
	@Test
	public void test50() {
		int[] array = {45, 56, 4, 35};
		for (int i = 1; i < array.length; i++) {
			for(int j = 0; j < i; j ++ ) {
				if(array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
			
		}
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
			
			
		}
	}
	@Test
	public void test51() {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串:");
		String str = scanner.nextLine();
		char[] array = str.toCharArray();
		int letterCount = 0;
		int numberCount = 0;
		int blankCount = 0;
		int otherCount = 0;
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
			if ((array[i] >= 'a' && array[i] <= 'z') 
					|| (array[i] >= 'A' && array[i] <= 'Z')) {
				letterCount++;
			} else if (array[i] >= '0' && array[i] <= '9') {
				numberCount++;
			} else if (array[i] == ' ') {
				blankCount++;
			} else {
				otherCount++;
			}
		}
		
		System.out.println("字母个数：" + letterCount);
		System.out.println("数字个数：" + numberCount);
		System.out.println("空格个数：" + blankCount);
		System.out.println("其他个数：" + otherCount);
	}
}
	




